package com.itheima.exam.Exam5;

import java.util.Comparator;
import java.util.Objects;

public class Student implements Comparable<Student> {
    private String name;
    private int physic;
    private int chemistry;

    @Override
    public int compareTo(Student other) {
        // 计算总分
        int thisTotal = this.physic + this.chemistry;
        int otherTotal = other.physic + other.chemistry;

        // 按总分从高到低排序（主要条件）
        if (thisTotal != otherTotal) {
            return Integer.compare(otherTotal, thisTotal); // 降序排列
        }

        // 总分相同时，按物理成绩从高到低排序（次要条件）
        return Integer.compare(other.physic, this.physic); // 降序排列
    }
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", physic=" + physic +
                ", chemistry=" + chemistry +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return physic == student.physic && chemistry == student.chemistry && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, physic, chemistry);
    }

    public Student() {
    }

    public Student(String name, int physic, int chemistry) {
        this.name = name;
        this.physic = physic;
        this.chemistry = chemistry;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPhysic() {
        return physic;
    }

    public void setPhysic(int physic) {
        this.physic = physic;
    }

    public int getChemistry() {
        return chemistry;
    }

    public void setChemistry(int chemistry) {
        this.chemistry = chemistry;
    }
}
